package com.godGuang.patient.controller;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.godGuang.common.core.domain.Result;
import com.godGuang.common.log.annotation.Log;
import com.godGuang.common.log.enums.BusinessType;
import com.godGuang.patient.service.ArchivesService;
import com.patient.domin.Archives;
import com.patient.domin.FollowDoctor;
import com.patient.domin.request.DoctorRequest;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
  * 前端控制器
 */
@Log4j2
@RestController
@RequestMapping("/archives")
public class ArchivesController {
    @Autowired
    private ArchivesService sysArchivesService;

    /**
     * @description: 查询档案
     * @author: Lxk
     * @date: 2024/1/8 20:52
     * @param: []
     * @return: com.godGuang.common.core.domain.Result<com.patient.domin.Archives>
     **/
    //@RequiresPermissions("system:archives:list")
    @PostMapping("/list")
    public Result<Archives> list()
    {
        Archives listArchives = sysArchivesService.selectSysArchivesList();
        System.out.println(listArchives);
        if (ObjectUtils.isEmpty(listArchives)){
            return Result.error(null,"您还没有档案哦");
        }
        return Result.success(listArchives);
    }





    /**
     * @description: 新增档案
     * @author: Lxk
     * @date: 2024/1/8 20:52
     * @param: [sysArchives]
     * +`
     * @return: com.godGuang.common.core.domain.Result
     **/
    //@RequiresPermissions("system:archives:add")
    @Log(title = "新增档案", businessType = BusinessType.INSERT)
    @PostMapping("/insertSysArchives")
    public Result add(@RequestBody Archives sysArchives)
    {
        if (ObjectUtils.isEmpty(sysArchives)){
        throw new RuntimeException("档案不能为空");
    }
        sysArchivesService.insertSysArchives(sysArchives);
        return Result.success("创建成功,请刷新页面查看详情","创建成功,请刷新页面查看详情");
    }

    /**
     * @description: 档案详情
     * @author: Lxk
     * @date: 2024/1/8 21:39
     * @param: [userId]
     * @return: com.godGuang.common.core.domain.Result
     **/
    @GetMapping("/selectInfoId/{archivesId}")
    public Result selectInfoId(@PathVariable("archivesId") Long archivesId)
    {
        if (null == archivesId){
            throw new RuntimeException("Invalid archivesId");
        }
        return Result.success(sysArchivesService.selectInfoId(archivesId));
    }


    /**
     * @description: 修改档案
     * @author: Lxk
     * @date: 2024/1/8 20:53
     * @param: [sysArchives]
     * @return: com.godGuang.common.core.domain.Result
     **/
    //@RequiresPermissions("system:archives:edit")
    @Log(title = "修改档案", businessType = BusinessType.UPDATE)
    @PostMapping("/updateArchives")
    public Result edit(@RequestBody Archives archives)
    {
        sysArchivesService.updateArchives(archives);
        return Result.success("档案修改成功");
    }

    /**
     * @description: 删除档案
     * @author: Lxk
     * @date: 2024/1/8 22:16
     * @param: [archivesIds]
     * @return: com.godGuang.common.core.domain.Result
     **/
    //@RequiresPermissions("system:archives:remove")
    @Log(title = "删除档案", businessType = BusinessType.DELETE)
    @GetMapping ("/remove/{archivesId}")
    public Result remove( @PathVariable("archivesId") Long archivesId)
    {
        if (null == archivesId){
            throw new RuntimeException("Invalid archivesId");
        }
        sysArchivesService.remove(archivesId);
        return Result.success("档案删除成功");
    }


    /**
     * @description: 关注
     * @author: Lxk
     * @date: 2024/1/11 14:05
     * @param: [doctorRequest]
     * @return: com.godGuang.common.core.domain.Result
     **/
    @Log(title = "关注", businessType = BusinessType.INSERT)
    @PostMapping("/follow")
    public Result follow(@RequestBody DoctorRequest doctorRequest)
    {
        sysArchivesService.follow(doctorRequest);
        return Result.success("关注成功");
    }

    /**
     * @description: 关注列表
     * @author: Lxk
     * @date: 2024/1/11 16:17
     * @param: []
     * @return: com.godGuang.common.core.domain.Result<java.util.List<com.patient.domin.FollowDoctor>>
     **/
    @Log(title = "关注列表")
    @PostMapping("/followList")
    public Result<List<FollowDoctor>> followList()
    {
        return Result.success(sysArchivesService.followList());
    }

    /**
     * @description: 取消关注
     * @author: Lxk
     * @date: 2024/1/11 17:04
     * @param: [followId]
     * @return: com.godGuang.common.core.domain.Result
     **/
    @Log(title = "取消关注", businessType = BusinessType.DELETE)
    @GetMapping ("/removeFollow/{followId}")
    public Result removeFollow(@PathVariable("followId") Long followId)
    {
        if (null == followId){
            throw new RuntimeException("Invalid follow");
        }
        sysArchivesService.removeFollow(followId);
        return Result.success("已取消关注");
    }


    /**
     * 导出档案
     */
    //@RequiresPermissions("system:archives:export")
    //@Log(title = "档案", businessType = BusinessType.EXPORT)
    //@PostMapping("/export")1
    //public void export(HttpServletResponse response, Archives sysArchives)
    //{
    //    List<Archives> list = sysArchivesService.selectSysArchivesList(sysArchives);
    //    ExcelUtil<Archives> util = new ExcelUtil<Archives>(Archives.class);
    //    util.exportExcel(response, list, "档案数据");
    //}



}
